var projectname = process.argv[3];
var glob = require("glob");
// const CleanWebpackPlugin = require('clean-webpack-plugin');
const outputDir = "../webapp";

function getEntry() {
  var entries = {};
  var BUILD = process.env.NODE_ENV == "production";

  var items = glob.sync(`src/modules/${BUILD ? projectname : "*"}/main.js`);
  for (var i in items) {
    var filepath = items[i];
    var fileList = filepath.split("/");
    var fileName = fileList[fileList.length - 2];
    entries[fileName] = {
      entry: filepath,
      // 模板来源
      template: `public/index.html`,
      // 在 dist/index.html 的输出
      filename: `${BUILD ? "index" : fileName + "/index"}.html`,
      // 提取出来的通用 chunk 和 vendor chunk。
      chunks: ["chunk-vendors", "chunk-common", fileName]
    };
  }
  return entries;
}
var pages = getEntry();
module.exports = {
  baseUrl: "./",
  productionSourceMap: false, // 生产禁止显示源代码
  outputDir: `${outputDir}/` + projectname,
  lintOnSave: false,
  //  outputDir: 'dist/' + projectname,
  pages: pages,
  configureWebpack: {
    externals: {
      vue: "Vue",
      vuex: "Vuex",
      axios: "axios",
      "vue-router": "VueRouter",
      iview: "iview"
    }
  },
  devServer: {
    proxy: {
      "/": {
        // target: 'http://iwecloud13:31837',
        // target: 'http://wectest2.wisedu.com',
        target: "http://wectest2.wisedu.com",
        // target: 'http://172.20.6.82:8080',
        //target:'http://172.20.6.205:8088',
        changeOrigin: true,
        ws: false // proxy websockets
      }
    }
  }
};
